<template>
  <div class="buyer-home">
    <el-header class="header">
      <div class="header-content">
        <h2>积分商城</h2>
        <div class="user-info">
          <span>欢迎，{{ currentUser.nickname || currentUser.username }}</span>
          <span class="points">积分：{{ userPoints.availablePoints }}</span>
          <el-button type="text" @click="logout">退出登录</el-button>
        </div>
      </div>
    </el-header>

    <el-container>
      <el-aside width="200px" class="sidebar">
        <el-menu :default-active="$route.path" router>
          <el-menu-item index="/buyer">
            <i class="el-icon-s-home"></i>
            <span slot="title">商品首页</span>
          </el-menu-item>
          <el-menu-item index="/buyer/orders">
            <i class="el-icon-s-order"></i>
            <span slot="title">兑换历史</span>
          </el-menu-item>
          <el-menu-item index="/buyer/points">
            <i class="el-icon-money"></i>
            <span slot="title">积分流水</span>
          </el-menu-item>
          <el-menu-item index="/buyer/profile">
            <i class="el-icon-user"></i>
            <span slot="title">个人信息</span>
          </el-menu-item>
          <el-menu-item index="/buyer/messages">
            <i class="el-icon-message"></i>
            <span slot="title">站内消息</span>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <el-main class="main-content">
        <router-view />
      </el-main>
    </el-container>
  </div>
</template>

<script>
export default {
  name: 'BuyerHome',
  data() {
    return {
      currentUser: {},
      userPoints: {
        availablePoints: 0
      }
    }
  },
  created() {
    this.loadUserInfo()
  },
  methods: {
    loadUserInfo() {
      const userStr = localStorage.getItem('user')
      if (userStr) {
        this.currentUser = JSON.parse(userStr)
      }
      // 这里可以调用API获取用户的积分信息
      // 暂时使用模拟数据
      this.userPoints.availablePoints = 5000
    },
    logout() {
      localStorage.removeItem('token')
      localStorage.removeItem('user')
      this.$router.push('/login')
    }
  }
}
</script>

<style scoped>
.buyer-home {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background-color: #409EFF;
  color: white;
  padding: 0;
  height: 60px;
  display: flex;
  align-items: center;
}

.header-content {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 20px;
}

.points {
  background-color: rgba(255, 255, 255, 0.2);
  padding: 5px 10px;
  border-radius: 4px;
}

.sidebar {
  background-color: #f5f5f5;
  border-right: 1px solid #e6e6e6;
}

.main-content {
  background-color: #f5f5f5;
  padding: 20px;
}
</style>
